﻿using System;
using System.Linq;
using System.Text;
using System.Globalization;

namespace DesignByFarooq.PowershellByExample
{
    public sealed class Tuple<T1, T2>
    {
        public T1 Item1 { get; private set; }
        public T2 Item2 { get; private set; }

        public Tuple(
            T1 item1,
            T2 item2
            )
        {
            this.Item1 = item1;
            this.Item2 = item2;
        }

        public override string ToString()
        {
            StringBuilder builder = new StringBuilder();
            
            builder.AppendFormat(
                CultureInfo.InvariantCulture,
                "({0},{1})",
                this.Item1,
                this.Item2
                );

            return builder.ToString();
        }

        public override bool Equals(
            object obj
            )
        {
            if (obj == null)
            {
                return false;
            }

            if (object.ReferenceEquals(this, obj) != false)
            {
                return true;
            }

            if (this.GetType() != obj.GetType())
            {
                return false;
            }

            Tuple<T1, T2> tuple = obj as Tuple<T1, T2>;

            return this.Equals(
                tuple
                );
        }

        private bool Equals(
            Tuple<T1, T2> tuple
            )
        {
            return this.Item1.Equals(tuple.Item1) && this.Item2.Equals(tuple.Item2);
        }
    }
}
